import QtQuick 1.1
//import com.nokia.symbian 1.1
import com.nokia.meego 1.0

Page {
    property variant coin

    function isVertical() {
        return (screen.currentOrientation === Screen.Portrait || screen.currentOrientation === Screen.PortraitInverted);
    }

    function imageWidth() {
        if (isVertical()) {
            if (images.width > images.height/2)
                return images.width;
            else
                return images.height/2;
        }
        else {
            if (images.width/2 > images.height)
                return images.width/2;
            else
                return images.height;
        }
    }

    Flickable {
        id: images
        anchors.fill: parent
        contentWidth: isVertical() ? imageWidth() : imageWidth()*2
        contentHeight: isVertical() ? imageWidth()*2 : imageWidth()

        Grid {
            columns: isVertical() ? 1 : 2
            rows: (2 - columns) + 1

            Image {
                width: imageWidth()
                height: imageWidth()
                source: imagePage.status === PageStatus.Active ? "data:image/png;base64," + coin.obverseimg : ""
                smooth: true
                fillMode: Image.PreserveAspectFit
            }
            Image {
                width: imageWidth()
                height: imageWidth()
                source: imagePage.status === PageStatus.Active ? "data:image/png;base64," + coin.reverseimg : ""
                smooth: true
                fillMode: Image.PreserveAspectFit
            }

            MouseArea {
                width: isVertical() ? imageWidth() : imageWidth()*2
                height: isVertical() ? imageWidth()*2 : imageWidth()
                onClicked: pageStack.pop()
            }
        }
    }

    onStatusChanged: {
        if (status === PageStatus.Activating) {
            images.contentX = 0;
            images.contentY = 0;
        }
    }

    ScrollDecorator {
        flickableItem: images
    }
}
